package com.clinic.entity.db;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = DrugIssue.TABLE)
public class DrugIssue implements Serializable{

	private static final long serialVersionUID = -4145555206245417325L;

	public static final String TABLE = "drugissue";
	
	public static final class Columns {
		public static final String DRUG_ISSUE_ID = "drugIssueId";
		public static final String TERMS_PER_DAY = "termsPerDay";
		public static final String NO_OF_DAYS = "noOfDays";
		public static final String AMOUNT = "amount";
		public static final String TREATMENT_TIME = "treatmentTime";
		public static final String ISSUE = "issue";
		public static final String DATE = "date";
		public static final String STATUS = "status";
		public static final String DRUG_ID = "drugId";
		public static final String DRUG_STOCK_ID = "drugStockId";
		public static final String PRESCRIPTION_ID = "prescriptionId";
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = Columns.DRUG_ISSUE_ID)
	private long drugIssueId;
	
	@Column(name = Columns.TERMS_PER_DAY)
	private int termsPerDay;
	
	@Column(name = Columns.NO_OF_DAYS)
	private int noOfDays;
	
	@Column(name = Columns.AMOUNT)
	private int amount;
	
	@Column(name = Columns.TREATMENT_TIME)
	private String treatmentTime;
	
	@Column(name = Columns.ISSUE)
	private boolean issue;
	
	@Column(name = Columns.DATE)
	private Date date;
	
	@Column(name = Columns.STATUS)
	private String status;
	
	@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = Columns.DRUG_ID)
	private Drug drug;
	
	@ManyToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name="drugstockissue",
	    joinColumns={@JoinColumn(name="drugIssueId")},
	    inverseJoinColumns={@JoinColumn(name="drugStockId")})
	private Set<DrugStock> drugStocks;
	
	@ManyToOne(cascade=CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = Columns.PRESCRIPTION_ID)
	private Prescription prescription;

	public long getDrugIssueId() {
		return drugIssueId;
	}

	public void setDrugIssueId(long drugIssueId) {
		this.drugIssueId = drugIssueId;
	}

	public int getTermsPerDay() {
		return termsPerDay;
	}

	public void setTermsPerDay(int termsPerDay) {
		this.termsPerDay = termsPerDay;
	}

	public int getNoOfDays() {
		return noOfDays;
	}

	public void setNoOfDays(int noOfDays) {
		this.noOfDays = noOfDays;
	}

	public int getAmount() {
		return amount;
	}

	public void setAmount(int amount) {
		this.amount = amount;
	}

	public String getTreatmentTime() {
		return treatmentTime;
	}

	public void setTreatmentTime(String treatmentTime) {
		this.treatmentTime = treatmentTime;
	}

	public boolean isIssue() {
		return issue;
	}

	public void setIssue(boolean issue) {
		this.issue = issue;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Drug getDrug() {
		return drug;
	}

	public void setDrug(Drug drug) {
		this.drug = drug;
	}

	public Set<DrugStock> getDrugStocks() {
		return drugStocks;
	}

	public void setDrugStocks(Set<DrugStock> drugStocks) {
		this.drugStocks = drugStocks;
	}

	public Prescription getPrescription() {
		return prescription;
	}

	public void setPrescription(Prescription prescription) {
		this.prescription = prescription;
	}

}
